package twoD.IsoPfem;

import inf.jlinalg.Array2DMatrix;
import inf.jlinalg.IMatrix;

public class RealTable {
	private double E_;
	private double nu_;
	private double t_;

	/**
	 * these parameters used for various problem: cracking, plasticity, ...
	 */
	private double ft_; // tensile strength

	/**
	 * these parameters was used for cracking problem
	 */
	private double Dnn_;
	private double Dss_;
	private double Gf_;

	public RealTable(double E, double nu) {
		this.E_ = E;
		this.nu_ = nu;
	}

	public RealTable(double E, double nu, double Dnn, double Dss) {
		this(E, nu);
		this.Dnn_ = Dnn;
		this.Dss_ = Dss;
	}

	public double getValue(int i) {
		switch (i) {
		case 1:
			return this.t_;
		case 2:
			return this.E_;
		case 3:
			return this.nu_;
		case 4:
			return this.Dnn_;
		case 5:
			return this.Dss_;
		default:
			return 0;
		}
	}

	public double getE() {
		return E_;
	}

	public void setE(double E) {
		E_ = E;
	}

	public double getK() {
		return E_ / (3 * (1 - 2 * nu_));
	}

	public double getG() {
		return E_ / (2 * (1 + nu_));
	}

	public double getLambda() {
		return E_ * nu_ / ((1 + nu_) * (1 - 2 * nu_));
	}

	public double getNu() {
		return nu_;
	}

	public void setNu(double nu) {
		this.nu_ = nu;
	}

	public double getThickness() {
		return t_;
	}

	public void setThickness(double t) {
		this.t_ = t;
	}

	public IMatrix getCPlaneStress() {
		Array2DMatrix c = new Array2DMatrix(3, 3);
		double f = E_ / (1 - nu_ * nu_);

		c.set(0, 0, f * 1);
		c.set(0, 1, f * nu_);
		c.set(1, 0, f * nu_);
		c.set(1, 1, f * 1);
		c.set(2, 2, f * (1 - nu_) / 2);
		return c;
	}

	public IMatrix getCPlaneStrain() {
		Array2DMatrix c = new Array2DMatrix(3, 3);
		double f = E_ / ((1 + nu_) * (1 - 2 * nu_));

		c.set(0, 0, f * (1 - nu_));
		c.set(0, 1, f * nu_);
		c.set(1, 0, f * nu_);
		c.set(1, 1, f * (1 - nu_));
		c.set(2, 2, f * (1 - 2 * nu_) / 2);
		return c;
	}

	public double getDnn() {
		return Dnn_;
	}

	public void setDnn(double dnn) {
		Dnn_ = dnn;
	}

	public double getDss() {
		return Dss_;
	}

	public void setDss(double dss) {
		Dss_ = dss;
	}

	public IMatrix getDhat2D() {
		IMatrix Dhat = new Array2DMatrix(2, 2);
		Dhat.set(0, 0, Dnn_);
		Dhat.set(1, 1, Dss_);
		return Dhat;
	}

	public IMatrix getDhat3D() {
		IMatrix Dhat = new Array2DMatrix(3, 3);
		Dhat.set(0, 0, Dnn_);
		Dhat.set(1, 1, Dss_);
		Dhat.set(2, 2, Dss_);
		return Dhat;
	}

	public double getTensileStrength() {
		return ft_;
	}

	public void setTensileStrength(double ft_) {
		this.ft_ = ft_;
	}

	public double getFractureEnergy() {
		return Gf_;
	}

	public void setFractureEnergy(double gf_) {
		Gf_ = gf_;
	}
}
